import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    msg: 'welcome to nanjing',
    name: 'tom',
    age: 18
  },
  getters: {
    msg2(state){
      return state.msg.split(' ').reverse().join(' ')
    }
  },
  mutations: {
    setMsg(state, newValue){
      state.msg = newValue
    }
  },
  actions: {
    setMessage(context){
      // 发送Ajax请求，获取数据
      var data = 'hello world'
      context.commit('setMsg', data)
    }
  },
  modules: {
  }
})
